/**
 * @author LKQ
 * @date 2022/1/30 17:12
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.reversePrefix("abcd", 'z'));
    }

    public String reversePrefix(String word, char ch) {
        StringBuffer sb = new StringBuffer();
        int first = 0;
        for (int i = 0; i < word.length(); i++) {
            char temp = word.charAt(i);
            if (first == 1) {
                sb.append(temp);
                continue;
            }
            if (temp != ch) {
                sb.append(temp);
            }else {
                sb.append(temp);
                String s = sb.reverse().toString();
                sb.replace(0, i+1, s);
                first = 1;
            }
        }
        return sb.toString();
    }
}
